// Reference Counted base class
// (c) jimon game studio

#ifndef JEH_JEUNKNOWN
#define JEH_JEUNKNOWN

#include "jeTypes.h"
#include "jeDebug.h"
#include "jeThreads.h"
#include "jeMemory.h"

namespace je
{
	//! Reference Counted base class
	class jeUnknown
	{
	private:
		//! Reference Count
		s32 _RefereceCount;

	public:
		//! Constructor
		jeUnknown()
			:_RefereceCount(1)
		{
		}

		//! Destructor
		virtual ~jeUnknown()
		{
		}

		//! Grab this object
		void Grab()
		{
			_RefereceCount++;
		}

		//! Drop this object
		u1 Drop()
		{
			JEASSERT(_RefereceCount > 0)
			_RefereceCount--;

			if (!_RefereceCount)
			{
				JEDELETE(this)
				return true;
			}
			else
				return false;

		}
	};
}

#endif
